from wtforms import StringField,IntegerField,Form
from wtforms.validators import number_range,input_required,length,ValidationError
from exts import db
from model.models import Desk


class DeskForm(Form):
    desk_name = StringField(validators=[input_required(message="桌子名为必填项"),length(min=1,max=20,message='请输入合适长度的桌子名')])
    men = IntegerField(validators=[input_required(message='人数为必填项'),number_range(min=0,max=30,message='可容纳人数不能超过30')])

    def validate_desk_name(self,field):
        desk = Desk.query.filter(Desk.desk_name==field.data).first()
        if desk is not None:
            raise ValidationError("桌子名重复")
        else:
            return True


class UpdateDeskForm(Form):
    desk_name = StringField(validators=[input_required(message='请输入信息'),length(min=1,max=20,message='请输入合适长度的信息')])
